//
//  KBMerPrtmissionView.swift
//
//  Created by admin on 2022/9/14.
//

import UIKit

class KBMerPrtmissionView: NSObject {

    enum prtmissionTypeEnum: String {
        case Network = "无线数据"
        case Location = "位置"
        case Camera = "相机"
        case PhotoLibrary = "相册"
        case Notification = "通知"
    }
    
    static var tipsView: KBAlertView? = nil
    class func show(type: prtmissionTypeEnum) {
        
        let title = "已为“\(AppInfo.appDisplayName)”关闭访问\(type.rawValue)权限"
        let content = "您可以在“设置”中为此App打开\(type == .Network ? "" : "访问" )\(type.rawValue)权限"
        
        tipsView = KBAlertView(title: title,content, cancelButtonTitle: (type == .Network ? nil : "取消"), otherButtonTitle: "立即打开") {
            let url = URL(string: UIApplication.openSettingsURLString)//应用设置
            if UIApplication.shared.canOpenURL(url!){
                UIApplication.shared.open(url!, options: [:], completionHandler: nil)
            }
            if (type == .Network) {
                if(tipsView != nil){
                    UIApplication.shared.keyWindow?.addSubview(tipsView!)
                }
            }
        } cancelBlock: {

        }
        tipsView?.sureIsRemove = false
        tipsView!.showView()
    }
    
    class func hide() {
        tipsView?.hideView(isRemove: true)
    }
    
}
